package com.jdk.demo.io.read返回负1;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {

	public static void main(String[] a) {
        try {
            ServerSocket sskt = new ServerSocket(10001);
            Socket skt = sskt.accept();
            while (true) {

                OutputStream out = skt.getOutputStream();
                byte[] buf = new byte[2];
                buf[0] = 0x0D;
                buf[1] = 0x0A;
                out.write(buf);
                out.flush();
                out.close(); // 如果这里关闭了。 就会返回-1；
                Thread.sleep(2000);

            }

        } catch (IOException e) {

            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }


}
